﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
	/// <summary>
	/// 数据访问类:workFlow
	/// </summary>
	public partial class workFlow
	{
		public workFlow()
		{}
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("workFlow_id", "workFlow");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int workFlow_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from workFlow");
            strSql.Append(" where workFlow_id=@workFlow_id");
            SqlParameter[] parameters = {
					new SqlParameter("@workFlow_id", SqlDbType.Int,4)
			};
            parameters[0].Value = workFlow_id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.workFlow model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into workFlow(");
            strSql.Append("document_id,flow_node_id,flow_node_num,person_id,workFlow_direction,workFlow_status,workFlow_time,workFlow_reson,workFlow_isWork,workFlow_submitId)");
            strSql.Append(" values (");
            strSql.Append("@document_id,@flow_node_id,@flow_node_num,@person_id,@workFlow_direction,@workFlow_status,@workFlow_time,@workFlow_reson,@workFlow_isWork,@workFlow_submitId)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@document_id", SqlDbType.Int,4),
					new SqlParameter("@flow_node_id", SqlDbType.Int,4),
					new SqlParameter("@flow_node_num", SqlDbType.TinyInt,1),
					new SqlParameter("@person_id", SqlDbType.Int,4),
					new SqlParameter("@workFlow_direction", SqlDbType.TinyInt,1),
					new SqlParameter("@workFlow_status", SqlDbType.TinyInt,1),
					new SqlParameter("@workFlow_time", SqlDbType.DateTime),
					new SqlParameter("@workFlow_reson", SqlDbType.VarChar,2000),
					new SqlParameter("@workFlow_isWork", SqlDbType.Bit,1),
					new SqlParameter("@workFlow_submitId", SqlDbType.Int,4)};
            parameters[0].Value = model.document_id;
            parameters[1].Value = model.flow_node_id;
            parameters[2].Value = model.flow_node_num;
            parameters[3].Value = model.person_id;
            parameters[4].Value = model.workFlow_direction;
            parameters[5].Value = model.workFlow_status;
            parameters[6].Value = model.workFlow_time;
            parameters[7].Value = model.workFlow_reson;
            parameters[8].Value = model.workFlow_isWork;
            parameters[9].Value = model.workFlow_submitId;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.workFlow model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update workFlow set ");
            strSql.Append("document_id=@document_id,");
            strSql.Append("flow_node_id=@flow_node_id,");
            strSql.Append("flow_node_num=@flow_node_num,");
            strSql.Append("person_id=@person_id,");
            strSql.Append("workFlow_direction=@workFlow_direction,");
            strSql.Append("workFlow_status=@workFlow_status,");
            strSql.Append("workFlow_time=@workFlow_time,");
            strSql.Append("workFlow_reson=@workFlow_reson,");
            strSql.Append("workFlow_isWork=@workFlow_isWork,");
            strSql.Append("workFlow_submitId=@workFlow_submitId");
            strSql.Append(" where workFlow_id=@workFlow_id");
            SqlParameter[] parameters = {
					new SqlParameter("@document_id", SqlDbType.Int,4),
					new SqlParameter("@flow_node_id", SqlDbType.Int,4),
					new SqlParameter("@flow_node_num", SqlDbType.TinyInt,1),
					new SqlParameter("@person_id", SqlDbType.Int,4),
					new SqlParameter("@workFlow_direction", SqlDbType.TinyInt,1),
					new SqlParameter("@workFlow_status", SqlDbType.TinyInt,1),
					new SqlParameter("@workFlow_time", SqlDbType.DateTime),
					new SqlParameter("@workFlow_reson", SqlDbType.VarChar,2000),
					new SqlParameter("@workFlow_isWork", SqlDbType.Bit,1),
					new SqlParameter("@workFlow_submitId", SqlDbType.Int,4),
					new SqlParameter("@workFlow_id", SqlDbType.Int,4)};
            parameters[0].Value = model.document_id;
            parameters[1].Value = model.flow_node_id;
            parameters[2].Value = model.flow_node_num;
            parameters[3].Value = model.person_id;
            parameters[4].Value = model.workFlow_direction;
            parameters[5].Value = model.workFlow_status;
            parameters[6].Value = model.workFlow_time;
            parameters[7].Value = model.workFlow_reson;
            parameters[8].Value = model.workFlow_isWork;
            parameters[9].Value = model.workFlow_submitId;
            parameters[10].Value = model.workFlow_id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int workFlow_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from workFlow ");
            strSql.Append(" where workFlow_id=@workFlow_id");
            SqlParameter[] parameters = {
					new SqlParameter("@workFlow_id", SqlDbType.Int,4)
			};
            parameters[0].Value = workFlow_id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string workFlow_idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from workFlow ");
            strSql.Append(" where workFlow_id in (" + workFlow_idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.workFlow GetModel(int workFlow_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 workFlow_id,document_id,flow_node_id,flow_node_num,person_id,workFlow_direction,workFlow_status,workFlow_time,workFlow_reson,workFlow_isWork,workFlow_submitId from workFlow ");
            strSql.Append(" where workFlow_id=@workFlow_id");
            SqlParameter[] parameters = {
					new SqlParameter("@workFlow_id", SqlDbType.Int,4)
			};
            parameters[0].Value = workFlow_id;

            Maticsoft.Model.workFlow model = new Maticsoft.Model.workFlow();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.workFlow DataRowToModel(DataRow row)
        {
            Maticsoft.Model.workFlow model = new Maticsoft.Model.workFlow();
            if (row != null)
            {
                if (row["workFlow_id"] != null && row["workFlow_id"].ToString() != "")
                {
                    model.workFlow_id = int.Parse(row["workFlow_id"].ToString());
                }
                if (row["document_id"] != null && row["document_id"].ToString() != "")
                {
                    model.document_id = int.Parse(row["document_id"].ToString());
                }
                if (row["flow_node_id"] != null && row["flow_node_id"].ToString() != "")
                {
                    model.flow_node_id = int.Parse(row["flow_node_id"].ToString());
                }
                if (row["flow_node_num"] != null && row["flow_node_num"].ToString() != "")
                {
                    model.flow_node_num = int.Parse(row["flow_node_num"].ToString());
                }
                if (row["person_id"] != null && row["person_id"].ToString() != "")
                {
                    model.person_id = int.Parse(row["person_id"].ToString());
                }
                if (row["workFlow_direction"] != null && row["workFlow_direction"].ToString() != "")
                {
                    model.workFlow_direction = int.Parse(row["workFlow_direction"].ToString());
                }
                if (row["workFlow_status"] != null && row["workFlow_status"].ToString() != "")
                {
                    model.workFlow_status = int.Parse(row["workFlow_status"].ToString());
                }
                if (row["workFlow_time"] != null && row["workFlow_time"].ToString() != "")
                {
                    model.workFlow_time = DateTime.Parse(row["workFlow_time"].ToString());
                }
                if (row["workFlow_reson"] != null)
                {
                    model.workFlow_reson = row["workFlow_reson"].ToString();
                }
                if (row["workFlow_isWork"] != null && row["workFlow_isWork"].ToString() != "")
                {
                    if ((row["workFlow_isWork"].ToString() == "1") || (row["workFlow_isWork"].ToString().ToLower() == "true"))
                    {
                        model.workFlow_isWork = true;
                    }
                    else
                    {
                        model.workFlow_isWork = false;
                    }
                }
                if (row["workFlow_submitId"] != null && row["workFlow_submitId"].ToString() != "")
                {
                    model.workFlow_submitId = int.Parse(row["workFlow_submitId"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select workFlow_id,document_id,flow_node_id,flow_node_num,person_id,workFlow_direction,workFlow_status,workFlow_time,workFlow_reson,workFlow_isWork,workFlow_submitId ");
            strSql.Append(" FROM workFlow ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" workFlow_id,document_id,flow_node_id,flow_node_num,person_id,workFlow_direction,workFlow_status,workFlow_time,workFlow_reson,workFlow_isWork,workFlow_submitId ");
            strSql.Append(" FROM workFlow ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM workFlow ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.workFlow_id desc");
            }
            strSql.Append(")AS Row, T.*  from workFlow T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "workFlow";
            parameters[1].Value = "workFlow_id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
		#region  ExtensionMethod

        //获取数据(判断是否需要会签，如果返回多条则需要会签)
        public DataSet GetWorkFlow(int flow_id, int flow_node_num)
        {
            string sql = "select * from approver as a inner join flow_node as f on(a.flow_node_id=f.flow_node_id) where flow_id="
                        + flow_id
                        + " and flow_node_num = "
                        + flow_node_num;

            return DbHelperSQL.Query(sql);
        }

        /// <summary>
        /// 查询待办审批公文
        /// </summary>
        /// <returns></returns>
        public DataSet GetDaiBanCheck(string workFlow_status, string person_id,int isWork,string flow_op)
        {
            string sql = " select * from VdocumentInfo as t  right join  "
                        + " (select distinct document_id from VWorkFlowMap as w inner join approver as a on(w.flow_node_id = a.flow_node_id)  "
                        + " where workFlow_status = "
                        + workFlow_status
                        + " and a.person_id = "
                        + person_id
                        + " and  workFlow_isWork = "//此流程节点是否激活
                        + isWork
                        + " and flow_op = '"
                        + flow_op//判断是哪个流程
                        +"' "
                        + ")X on(t.document_id = X.document_id) "
                        + " where status=1 or status=0 "
                        + " order by inputtime desc ";

            return DbHelperSQL.Query(sql);
        }

        /// <summary>
        /// 查询待办审批公文(没有内联approver)
        /// </summary>
        /// <returns></returns>
        public DataSet GetDaiBanCheckByPerson(string workFlow_status, string person_id, int isWork, string flow_op)
        {
            string sql = " select * from VdocumentInfo as t  right join  "
                        + " (select document_id from VWorkFlowMap as w   "
                        + " where workFlow_status = "
                        + workFlow_status
                        + " and person_id = "
                        + person_id
                        + " and  workFlow_isWork = "//此流程节点是否激活
                        + isWork
                        + " and flow_op = '"
                        + flow_op//判断是哪个流程
                        + "' "
                        + ")X on(t.document_id = X.document_id) "
                        + " where status=1 or status=0 "
                        + " order by inputtime desc ";

            return DbHelperSQL.Query(sql);
        }

        
        /// <summary>
        /// 查询已办审批公文
        /// </summary>
        /// <returns></returns>
        public DataSet GetYiBanCheck(string person_id,int isWork,string flow_op)
        {
            string sql = " select * from VdocumentInfo as t  right join  "
                        + " (select document_id from VWorkFlowMap as w inner join approver as a on(w.flow_node_id = a.flow_node_id)  "
                        + " where workFlow_status <> 0 "
                        + " and a.person_id = "
                        + person_id
                         + " and  workFlow_isWork = "//此流程节点是否激活
                        + isWork
                        + " and flow_op = '"
                        + flow_op//判断是哪个流程
                        + "' "
                        + ")X on(t.document_id = X.document_id) "
                        + " where status=1 or status=0 "
                        + " order by inputtime desc ";

            return DbHelperSQL.Query(sql);
        }
        //获取下一步审核人节点ID
        public int GetFlow_node_id(int person_id,int document_id,int flow_node_num,int flow_id)
        {
            string sql = " select flow_node_id from VworkFlowWithFlowInfo where person_id="
                        + person_id
                        + " and document_id="
                        + document_id
                        + " and flow_node_num="
                        + flow_node_num
                        + " and flow_id = "+flow_id;
                        //+" and workFlow_status <> 1 ";

            DataSet ds = DbHelperSQL.Query(sql);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
            }
            else
            {
                return -1;
            }
            
            
        }
        /// <summary>
        /// 在workFlow表中修改本身意见
        /// </summary>
        /// <param name="person_id"></param>
        /// <param name="document_id"></param>
        /// <param name="workFlow_status"></param>
        /// <param name="workFlow_reson"></param>
        /// <param name="time"></param>
        /// <param name="flow_node_id">当前节点</param>
        /// <param name="flow_node_num">当前步骤</param>
        /// <returns></returns>
        public bool Update(int person_id, int document_id, int workFlow_status, string workFlow_reson, DateTime time, int flow_node_id_now, int flow_node_num_now)
        {
            string sql = " Update workFlow set workFlow_status = "
                        + workFlow_status
                        + ",workFlow_reson = '"
                        + workFlow_reson
                        + "',workFlow_time='"
                        + time
                        + "' where person_id="
                        + person_id
                        + " and document_id="
                        + document_id
                        + " and flow_node_id= "
                        + flow_node_id_now
                        + " and flow_node_num= "
                        + flow_node_num_now;

            if (DbHelperSQL.ExecuteSql(sql) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

       /// <summary>
       /// 
       /// </summary>
       /// <param name="workFlow_status"></param>
       /// <param name="workFlow_reson"></param>
       /// <param name="time"></param>
       /// <param name="workFlow_id"></param>
       /// <returns></returns>
        public bool Update( int workFlow_status, string workFlow_reson, DateTime time, string workFlow_id)
        {
            string sql = " Update workFlow set workFlow_status = "
                        + workFlow_status
                        + ",workFlow_reson = '"
                        + workFlow_reson
                        + "',workFlow_time='"
                        + time
                        + "' where workFlow_id="
                        + workFlow_id;

            if (DbHelperSQL.ExecuteSql(sql) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 获取所有审批状态的数量
        /// </summary>
        /// <param name="i">0、未审批，1、同意，2、否决(退回首节点),3、退签（退回上一节点）</param>
        /// <param name="person_id"></param>
        /// <param name="document_id"></param>
        /// <param name="flow_node_num">当前公文审核的节点编号</param>
        /// <param name="flow_node_id">
        /// 当前公文审核的节点ID（主要是为获取此公文流程在此节点编号下的所有其他节点 ，由于数据库workFlow表中无flow_id字段，所以只能通过flow_node_id和flow_node_num查找）
        /// </param>
        /// <returns></returns>
        public int GetCount(int i, int person_id, int document_id, int flow_node_num, int flow_node_id)
        {
            string sql = " select count(workFlow_status) as counts from workFlow where 1=1 "
                        + " and document_id= "
                        + document_id
                        + " and flow_node_num = "
                        + flow_node_num
                        + " and flow_node_id in "
                        + " (select flow_node_id from flow_node where flow_id = (select flow_id from flow_node where flow_node_id = "
                        + flow_node_id
                        + ") and flow_node_num = "
                        + flow_node_num
                        + ") "
                        + " and workFlow_status = "
                        + i;


            return Convert.ToInt32(DbHelperSQL.Query(sql).Tables[0].Rows[0][0].ToString());

        }
        /// <summary>
        /// 获取所有审批状态的数量
        /// </summary>
        /// <param name="i">0、未审批，1、同意，2、否决(退回首节点),3、退签（退回上一节点）</param>
        /// <param name="person_id"></param>
        /// <param name="document_id"></param>
        /// <param name="flow_node_num">当前公文审核的节点编号</param>
        /// <param name="flow_node_id">
        /// 当前公文审核的节点ID（主要是为获取此公文流程在此节点编号下的所有其他节点 ，由于数据库workFlow表中无flow_id字段，所以只能通过flow_node_id和flow_node_num查找）
        /// </param>
        /// <returns></returns>
        public int GetCountAll(int person_id, int document_id, int flow_node_num, int flow_node_id)
        {
            string sql = " select count(workFlow_status) as counts from workFlow where 1=1 "
                        + " and document_id= "
                        + document_id
                        + " and flow_node_num = "
                        + flow_node_num
                        + " and flow_node_id in "
                        + " (select flow_node_id from flow_node where flow_id = (select flow_id from flow_node where flow_node_id = "
                        + flow_node_id
                        + ") and flow_node_num = "
                        + flow_node_num
                        + ") ";

            return Convert.ToInt32(DbHelperSQL.Query(sql).Tables[0].Rows[0][0].ToString());
        }

        //根据节点号 获取流程下此节点号的所有节点
        public DataSet GetFlowNodeByFlow_idAndFlow_node_num(int flow_id, int flow_node_num)
        {
            string sql = " select * from flow_node as f inner join approver as a on(a.flow_node_id=f.flow_node_id) where f.flow_id="
                        + flow_id
                        + " and f.flow_node_num="
                        + flow_node_num
                        + " ";

            return DbHelperSQL.Query(sql);
        }

        //根据节点号 获取流程下此节点号的所有节点(没有内联approver，手工确定下一节点审批人)
        public DataSet GetFlowNodeByFlow_idAndFlow_node_numSend(int flow_id, int flow_node_num)
        {
            string sql = " select * from flow_node as f  where f.flow_id="
                        + flow_id
                        + " and f.flow_node_num="
                        + flow_node_num
                        + " ";

            return DbHelperSQL.Query(sql);
        }

        //获取当前审核人节点
        public int GetFlow_node_id_now(int person_id, int document_id, int flow_node_num)
        {
            string sql = " select flow_node_id from workFlow where person_id="
                        + person_id
                        + " and document_id="
                        + document_id
                        + " and flow_node_num="
                        + flow_node_num
                        + " "
                        + " and workFlow_status =0 ";

            DataSet ds = DbHelperSQL.Query(sql);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
            }
            else
            {
                return -1;
            }
            
        }

        //根据节点号 获取流程下此节点号的所有节点
        public DataSet GetFlowInfo(int document_id)
        {
            string sql = " select * from VWorkFlowInfo where document_id="
                        + document_id;
                        

            return DbHelperSQL.Query(sql);
        }


        /// <summary>
        /// 查询待办招标计划审核公文
        /// </summary>
        /// <returns></returns>
        public DataSet GetDaiBanBidCheck(string workFlow_status, string person_id,string flow_op)
        {
            string sql = " select * from VdocumentInfo as t  right join  "
                        + " (select distinct document_id from VWorkFlowMap as w inner join approver as a on(w.flow_node_id = a.flow_node_id)  "
                        + " where workFlow_status = "
                        + workFlow_status
                        + " and a.person_id = "
                        + person_id
                        + " and flow_op= '"
                        + flow_op
                        + "' "
                        + ")X on(t.document_id = X.document_id) "
                        + " where status=1 or status=0 "
                        + " order by inputtime desc ";

            return DbHelperSQL.Query(sql);
        }

        /// <summary>
        /// 查找审核的上一步信息
        /// </summary>
        /// <param name="document_id"></param>
        /// <param name="flow_node_id"></param>
        /// <param name="flow_node_num_now"></param>
        /// <returns>null：代表没有上一步流程，即当前流程走到了第一步，再返回时就到了提交者了</returns>
        public DataSet GetLastWorkFlowInfo(string document_id,string flow_node_id_now,int flow_node_num_now)
        {
            DataSet ds = null;

            Maticsoft.DAL.documentFlowInfo dm = new documentFlowInfo();

            DataSet ds_dfi = dm.GetList(" document_id= " + document_id);
            //获取当前流程信息
            if ( ds_dfi.Tables[0].Rows.Count == 1)
            {
                string[] flow_map_ids = ds_dfi.Tables[0].Rows[0]["flow_ids"].ToString().Split('|');

                if (flow_map_ids.Length > 1)
                {
                    string fristId = flow_map_ids[1].ToString();

                    //如果当前流程是第一步流程且在第一步
                    if (fristId == ds_dfi.Tables[0].Rows[0]["flow_id"].ToString()
                        && ds_dfi.Tables[0].Rows[0]["flow_node_id_now"].ToString() == "1")
                    {
                        ds = null;
                    }
                    else
                    {
                        string now_sql = " select * from flow_node where flow_node_id = " + flow_node_id_now
                            + " and flow_id = " + ds_dfi.Tables[0].Rows[0]["flow_id"];

                        DataSet ds_flow_node_now = DbHelperSQL.Query(now_sql);//获取当前flow_node信息

                        if (ds_flow_node_now.Tables[0].Rows.Count == 1)
                        {
                            string flow_id = ds_flow_node_now.Tables[0].Rows[0]["flow_id"].ToString();

                            string last_sql = " select flow_node_id from flow_node where flow_id= " + flow_id
                                + " and flow_node_num =" + (flow_node_num_now - 1);

                            DataSet ds_flow_node_last = DbHelperSQL.Query(last_sql);//获取上一步节点主键

                            if (ds_flow_node_last.Tables[0].Rows.Count == 1)
                            {
                                string flow_node_id_last = ds_flow_node_last.Tables[0].Rows[0]["flow_node_id"].ToString();

                                string sql = " select * from workflow  where document_id=" + document_id + " and flow_node_id= "
                                    + flow_node_id_last + " order by workFlow_id desc ";

                                ds = DbHelperSQL.Query(sql);
                            }

                        }
                    }
                }
            }

            #region
            //if (flow_node_num_now != 1)//如果不是流程的第一步
            //{
            //    string now_sql = " select * from flow_node where flow_node_id = " + flow_node_id_now;

            //    DataSet ds_flow_node_now = DbHelperSQL.Query(now_sql);//获取当前flow_node信息

            //    if (ds_flow_node_now.Tables[0].Rows.Count == 1)
            //    {
            //        string flow_id = ds_flow_node_now.Tables[0].Rows[0]["flow_id"].ToString();

            //        string last_sql = " select flow_node_id from flow_node where flow_id= " + flow_id
            //            + " and flow_node_num =" + (flow_node_num_now - 1);

            //        DataSet ds_flow_node_last = DbHelperSQL.Query(last_sql);//获取上一步节点主键

            //        if (ds_flow_node_last.Tables[0].Rows.Count == 1)
            //        {
            //            string flow_node_id_last = ds_flow_node_last.Tables[0].Rows[0]["flow_node_id"].ToString();

            //            string sql = " select * from workflow  where document_id=" + document_id + " and flow_node_id= "
            //                + flow_node_id_last + " order by workFlow_id desc ";

            //            ds = DbHelperSQL.Query(sql);
            //        }

            //    }

            //}
            #endregion

            return ds;
        }
        /// <summary>
        /// 查找审核信息
        /// </summary>
        /// <param name="document_id"></param>
        /// <param name="flow_node_id"></param>
        /// <param name="flow_node_num_now"></param>
        /// <returns></returns>
        public DataSet GetNowWorkFlowInfo(string document_id, string flow_node_id_now, int flow_node_num_now)
        {
            DataSet ds = null;

            string sql = " select * from workFlow where document_id= " + document_id
                + " and flow_node_id= " + flow_node_id_now + " and flow_node_num = " + flow_node_num_now
                + " and workFlow_status = 0 ";

            ds = DbHelperSQL.Query(sql);

            return ds;
        }
        /// <summary>
        /// 获取审核信息
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetWorkFlowInfo(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM VworkFlowUser ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

		#endregion  ExtensionMethod
	}
}

